package lesson4;

import java.util.Scanner;

public class Task2 {

		public static void main(String[] args) {
			
			Scanner s = new Scanner(System.in);
			String[] names = new String[10];
			double[] salaries = new double[10];
			
			for(int i = 0; i < names.length; i++)
			{
				System.out.println("Enter name of worker " + (i+1));
				names[i] = s.next();
				System.out.println("Enter salary of worker " + (i+1));
				salaries[i] = s.nextDouble();
			}
			
			int maxSalaryIndex = 0;
			int minSalaryIndex = 0;
			double maxSalary = salaries[0];
			double minSalary = salaries[0];
			
			double sum = salaries[0];
			
			for(int i = 1; i < salaries.length; i++)
			{
				sum += salaries[i];
				if(salaries[i] > maxSalary)
				{
					maxSalary = salaries[i];
					maxSalaryIndex = i;
				}
				if(salaries[i] < minSalary)
				{
					minSalary = salaries[i];
					minSalaryIndex = i;
				}
					
			}
			
			System.out.println("Richest worker is " + names[maxSalaryIndex]);
			System.out.println("His salary is " + salaries[maxSalaryIndex]);

			System.out.println("Poorest worker is " + names[minSalaryIndex]);
			System.out.println("His salary is " + salaries[minSalaryIndex]);
			
			System.out.println("Sum of all salaries = " + sum);
			
			System.out.println("Avg of all salaries = " + sum/salaries.length);
		}
}
